<template>
    <div>
        <h3>会员权益添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">会员权益名称</td>
                    <td><input type="text"  v-model="queryInfo.rightName"/></td>
                </tr>
                
                <tr>
                    <td align="right">权益状态</td>
                    <td>
                    <input type="radio" name="state" v-model="queryInfo.state"  :value="1"/>是
                    <input type="radio" name="state" v-model="queryInfo.state" :value="0"/>否
                    </td>
                </tr>
                <tr>
                    <td align="right">权益备注</td>
                    <td>
                        <textarea  v-model="queryInfo.desc" cols="50" rows="5"></textarea>
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="添加"  class="btn btn-primary"  @click="ok"/></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import moment, { lang } from 'moment';
import { reactive,ref,onMounted } from 'vue';
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';
const router = useRouter();
const route = useRoute();
let queryInfo = reactive({
  rightName: '',
  state: 1,
  desc: '',
 })
 const ok = () => {
     if(queryInfo.rightName == ''){
         alert('请输入权益名称');
         return;
     }
     if(queryInfo.desc == ''){
         alert('请输入权益备注');
         return;
     }
     if(queryInfo.desc.length>20){
        alert('权益备注不能超过50个字');
        return;
     }
     axios({
         url: '/api/User/AddUserRight',
         method: 'post',
         data: queryInfo
     })
     .then(res => {
        if(res.data == -1){
            alert('该权益名称已存在');
            return;
        }
         if(res.data>0){
            alert('添加成功');
            router.push('/useRtightList')
         }
         else{
            alert('添加失败');
         }
     })
     .catch(err => {
         console.log(err);
     })

 }
</script>

<style scoped>

</style>